var TChannelAsThrift = require('tchannel/as/thrift');
var TChannel = require('tchannel');
var fs = require('fs');
var path = require('path');
// var thrift = require('thrift');
var Int64 = require('node-int64');
var int64_util = require('./node_modules/thrift/lib/nodejs/lib/thrift/int64_util');
var client = TChannel();
var echoChannel = client.makeSubChannel({
    serviceName: 'echo1',
    peers: ['127.0.0.1:4030']
});
var tchannelAsThrift = TChannelAsThrift({
    channel: echoChannel,
    entryPoint: path.join(__dirname, 'thrifts/echo.thrift')
});
// var bufstarttime = new Buffer('11111111');
//  var int64 = new Int64('18567237648521729');
var int64 = int64_util.fromDecimalString('18567237648521729');
console.log(int64_util.toDecimalString(int64));
tchannelAsThrift.request({
    serviceName: 'echo',
    headers: {
        cn: 'echo'
    },
    hasNoParent: true
}).send('Echo::echo', {
    someHeader: 'headerValue'
}, {
    value:  int64.toBuffer()
}, onResponse);

function onResponse(err, res) {
    if (err) {
        console.log('got error', err);
    } else {
        console.log('got response', res);
    }
    client.close();
}
